package com.loveweinuo.jpush;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import org.json.JSONException;
import org.json.JSONObject;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by 86178 on 2019/8/9.
 * author mogen
 * 用心，成就一切。
 */


public class MyReceiver extends BroadcastReceiver {

    Context mContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        Bundle bundle = intent.getExtras();

        if (!TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA)) && bundle.getString(JPushInterface.EXTRA_EXTRA) != null) {
            if (bundle.getString(JPushInterface.EXTRA_EXTRA).contains("lizard")) {
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
                    String result = jsonObject.getString("lizard");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            //                LogUtil.e("极2 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光2 extra  :" + bundle.getString(JPushInterface.EXTRA_EXTRA));
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            //                LogUtil.e("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("极3 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光3 extra  :" + bundle.getString(JPushInterface.EXTRA_EXTRA));
        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            //                title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
            //                message = bundle.getString(JPushInterface.EXTRA_ALERT);
            //                LogUtil.e("极4 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光4 extra  :" + bundle.getString(JPushInterface.EXTRA_ALERT));
        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            //                LogUtil.e("极5 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光5 extra  :" + bundle.getString(JPushInterface.EXTRA_ALERT));
            if (bundle.getString(JPushInterface.EXTRA_EXTRA).contains("lizard")) {
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
                    String result = jsonObject.getString("lizard");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
            //                LogUtil.e("极6 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光6 extra  :" + bundle.getString(JPushInterface.EXTRA_ALERT));
            //                LogUtil.e("[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_ALERT));
        } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
            //                LogUtil.e("极7 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光7 extra  :" + bundle.getString(JPushInterface.EXTRA_ALERT));
            //                boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
            //                LogUtil.e("[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
        } else {
            //                LogUtil.e("极8 message:" + bundle.getString(JPushInterface.EXTRA_MESSAGE));
            //                LogUtil.e("光8 extra  :" + bundle.getString(JPushInterface.EXTRA_ALERT));
            //                LogUtil.e("[MyReceiver] Unhandled intent - " + intent.getAction());
        }
    }
}



